<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
< c:set var = "path" value = "${pageContext.request.contextPath} " />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色管理</title>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery1.9.0.min.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/xcConfirm.css"/>
<script src="${pageContext.request.contextPath }/js/xcConfirm.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	$(document).ready(function(){
		operation();
	});
	
	
	function saveUpdate(){
   		$.ajax({
   			url:'saveUpdateAction.action',//请求的远程url
   			data:$("#actionForm").serialize(),//发送到服务器的数据
   			type:"POST",//默认值: "GET")。请求方式 ("POST" 或 "GET")
   			dataType:"json",//服务器返回的数据类型，有几种返回类型：xml,html,script,json,text(默认)
   			success:function(data){ //请求成功后的回调函数
   				var jsonMap = eval("(" + data + ")");
   				var res = jsonMap.res;
   				var re = jsonMap.re;
   				if(res == true){
   					var txt=  "修改成功";
					window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.success);
   				}else{
   					var txt=  "修改失败,"+re;
					window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
   				}
   			}
   		});
	}
	
	//与后台交互的ajax
	function operation(){
   		$.ajax({
   			url:'editRoleAction.action',//请求的远程url
   			data:$("#actionForm").serialize(),//发送到服务器的数据
   			type:"POST",//默认值: "GET")。请求方式 ("POST" 或 "GET")
   			dataType:"json",//服务器返回的数据类型，有几种返回类型：xml,html,script,json,text(默认)
   			success:function(data){ //请求成功后的回调函数
   			}
   		});
	}
</script>
<style type="text/css">
  .label-class{background-image:url(${pageContext.request.contextPath }/img/chacunclick.png) }
  .css-a{text-decoration: none;color: #FFFFFF}
  td{text-align: center;height:35px; }
</style>
</head>
<body>
   <div>
     <form id="actionForm" method="post">
         <input type="hidden" name="roleId" value="<%=request.getParameter("roleId") %>" />
         <input type="hidden" name="roleInfoId" value="${sessionScope.roleInfo.roleid }" />
         <div>
               <table width="100%">
                  <tr>
                      <td width="80%"></td>
                      <td width="10%" class="label-class"><label><a href="editRole.jsp" class="css-a">查看详情</a></label></td>
                      <td width="10%" class="label-class"><label><a href="roleManage.jsp" class="css-a">返回</a></label></td>
                  </tr>
               </table>
         </div>
         <div>
            <table width="100%">
            <tr>
              <td width="10%"><label>角色名称:</label></td>
              <td><input size="30"  type="text" name="roleName" value="${sessionScope.roleInfo.rolename }"></input></td>
            </tr>
            <tr>
              <td width="10%"><label>角色描述:</label></td>
              <td><input size="30"  type="text" name="roleDescr" value="${sessionScope.roleInfo.roledescr }"></input></td>
            </tr>
            <tr>
              <td width="10%">状态:</td>
              <td>
                <select name="rolestatus">
                   <option value="1">启用</option>
                   <option value="0">禁用</option>
                </select>
              </td>
            </tr>
         </table>
         </div>    
         <div id="div-role" > 
           <c:forEach var="editparMap" items="${sessionScope.editparMap }">
             <dl>
               <dt>${editparMap.value.functionname }</dt>
                 <c:forEach var="funcMap" items="${sessionScope.funcMap }">
                  <c:if test="${funcMap.key.parentid == editparMap.value.functionid }">
                     <c:choose>
	                     <c:when test="${funcMap.value == '1' }">
	                        <dd><input type="checkbox" value="${funcMap.key.functionid }" name="func" checked="checked">${funcMap.key.functionname }</dd>
	                     </c:when>
	                     <c:otherwise>
	                        <dd><input type="checkbox" value="${funcMap.key.functionid }" name="func" >${funcMap.key.functionname }</dd>
	                     </c:otherwise>
                      </c:choose>                                  
                  </c:if>
                 </c:forEach>
             </dl>
            </c:forEach>
	       <%
			 session.removeAttribute("roleInfo");
	         session.removeAttribute("editparMap");
	         session.removeAttribute("funcMap");
		   %>
		   
		   <table width="100%">
              <tr>
                  <td width="90%"></td>
                  <td width="10%" class="label-class"><label><a href="#" onclick="saveUpdate()" class="css-a">保存</a></label></td>
              </tr>
          </table>
		   
         </div>
     </form>
   </div>
</body>
</html>